package h0711;

import java.util.*;

/**
  * @description 多线段数据压缩
  * @author 不知名帅哥
  * @date 2024/7/11 15:58
  * @version 1.0
*/
public class MultiSegmentDataCompression {
    static class Coordinate{
        int X;
        int Y;
        public Coordinate(int x,int y){
            this.X=x;
            this.Y=y;
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        List<Coordinate> coordinateList=new ArrayList<>();
        while (sc.hasNextInt()){
            int x = sc.nextInt();
            int y=sc.nextInt();
            coordinateList.add(new Coordinate(x,y));
        }
        //思路：根据拐点来判断。方向变化必是拐点。
        List<Coordinate> res=getResult(coordinateList);
        StringJoiner sj=new StringJoiner(" ");
        for (Coordinate re : res) {
            sj.add(re.X+"");
            sj.add(re.Y+"");
        }
        System.out.println(sj.toString());
    }


    private static List<Coordinate> getResult(List<Coordinate> coordinateList) {
        //只有两个点直接输出
        if (coordinateList.size()<3){
            return coordinateList;
        }

        List<Coordinate> res=new ArrayList<>();
        res.add(coordinateList.get(0)); //添加第一个点

        Coordinate prev=coordinateList.get(0);
        double slope=Double.NaN;
        int k=0;
        for (int i = 1; i < coordinateList.size()-1; i++) {
            Coordinate curr=coordinateList.get(i);
            Coordinate next=coordinateList.get(i+1);

            int dir1=direction(prev,curr);
            int dir2=direction(curr,next);
            //TODO 方向不同，有拐点，将中间的关键点加入进去。
            if (dir1!=dir2){
                res.add(curr);
            }
            prev=curr;
        }
        //添加最后一个节点
        res.add(coordinateList.get(coordinateList.size()-1));
        return res;
    }

    private static int direction(Coordinate c1,Coordinate c2){
        int dy=c2.Y-c1.Y;
        int dx=c2.X-c1.X;
        if (dy==0){
            return (dx>0)?1:-1; //横向
        }else if (dx==0){
            return (dy>0)?2:-2; //纵向
        }else {
            return dy==dx?3:-3;  //斜向45°
        }
    }
}
